class ShowLogs::Show::PostsController < ApplicationController
  def index
    @article = Article.find params[:article_id]
    #初始化日志浏览的评论
    @post = Post.new :article_id => @article.id,
      :created_by_valleyer_id => current_valleyer_id
  end

  def new
    @article = Article.find params[:article_id]
    @post = Post.new :post_session_id => params[:session_id],
      :created_by_valleyer_id => current_valleyer_id
  end

  def create
    @post = Post.new params[:post]
    if @post.post_session.nil?
      @post.post_session = PostSession.new :article_id => params[:post][:article_id],
        :created_by_valleyer_id => current_valleyer_id
      @post.post_session.save
    else
      @post.article_id = @post.post_session.article_id
    end
    @post.save
    @article = @post.article
    @old_post = @post
    @post = Post.new :article_id => @post.article_id,
      :post_session_id => @post.post_session_id,
      :created_by_valleyer_id => current_valleyer_id
  end

  def destroy
    @post = Post.find params[:id]
    @article = @post.article
    if @post.post_session.posts.length == 1
      @post.post_session.destroy
    end
    @post.destroy
  end
end
